<?php
require_once 'config.php';
?>
<?php
/* 查找笑话表
 * @return array
 *  */
function getjoke(){
    $sqlGet="SELECT * FROM joke  ORDER BY jokeId desc";
    $result=getQuery($sqlGet);
    return $result; //返回数组
}
//var_dump(getjoke());

/* 查找热门作者表
 * @return array
 *  */
function getwriter(){
    $sqlGet="SELECT * FROM Hot_writer  ORDER BY writerId desc";
    $result=getQuery($sqlGet);
    return $result; //返回数组
}
/* 查找书评表
 * @return array
 *  */
function getreview(){
    $sqlGet="SELECT * FROM review  ";
    $result=getQuery($sqlGet);
    return $result; //返回数组
}
//根据用户编号查询用户名字
function  getusername($uId)
{
    $sqlGet="select uname from User,review where user.uId=review.uId and review.uId=$uId";
    $result=getQuery($sqlGet);
    return $result;
}

//根据数据编号查询书籍名字
function  getbookname($bookId)
{
    $sqlGet="select bookName from book,review where book.bookId=review.bookId and review.bookId=$bookId";
    $result=getQuery($sqlGet);
    return $result;
}
//var_dump(getbookname());

//计算热门推荐总页数
function findCountHot_writer(){
    $strQuery = "select count(*) as nums from Hot_writer";
    $rs = getQuery($strQuery);//执行统计
    $value = 0;
    if(count($rs)>0){//判断是否成功执行
        $value = $rs[0]["nums"];
    }
    return $value;
}
//var_dump(findCountHot_writer());
//热门作者分页
function findListHot_writer($page){
    $pageSize=$GLOBALS["cfg"]["server"]["page_size"];
    if($page >= 1){//分页处理
        $page --;
    }
    $page *= $pageSize;
    //分页查询
    $strQuery = "SELECT * FROM Hot_writer order by writerId limit $page,$pageSize";
    $rs = getQuery($strQuery);//执行查询
    return $rs;
}
//var_dump(findListHot_writer(2));
?>